package com.example.manyhelloworld

import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.manyhelloworld.R
import java.util.Locale

class MainActivity : AppCompatActivity() {

    private lateinit var textView: TextView
    private lateinit var button: Button
    private lateinit var flagImageView: ImageView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        textView = findViewById(R.id.textView)
        button = findViewById(R.id.button)
        flagImageView = findViewById(R.id.flagImageView)

        val currentLocale = Locale.getDefault()
        when (currentLocale.language) {
            "zh" -> {
                flagImageView.setImageResource(R.drawable.flag_cn)
            }
            "ja" -> {
                flagImageView.setImageResource(R.drawable.flag_jp)
            }
            else -> {
                flagImageView.setImageResource(R.drawable.flag_us)
            }
        }

        button.setOnClickListener {
            when (currentLocale.language) {
                "zh" -> {
                    textView.text = getString(R.string.hello_world_zh)
                }
                "ja" -> {
                    textView.text = getString(R.string.hello_world_jp)
                }
                else -> {
                    textView.text = getString(R.string.hello_world_en)
                }
            }
        }
    }
}